import React from 'react';
import { Button } from 'antd';
import PropTypes from 'prop-types';

// 一个长得像按钮的文件上传input
class FileButton extends React.Component {
  render() {
    const { onChange, ...rest } = this.props;
    return (
      <Button type="primary" style={{ position: 'relative' }} {...rest} >
        <input type="file" style={{ position: 'absolute', opacity: 0 }} onChange={onChange} />
        {
          this.props.children
        }
      </Button>
    );
  }
}

FileButton.propTypes = {
  onChange: PropTypes.func, // 文件监听函数
};

FileButton.defaultProps = {
  onChange: () => null,
};

export default FileButton;
